﻿var pageMod = require("page-mod");
var data = require("self").data;

exports.main = function() {
	
	var scriptFilesSingle = [data.url("jquery.min.js"), data.url("functions.js"), data.url('singleVideo.js')];
	var scriptFilesChannels = [data.url("jquery.min.js"), data.url("functions.js"), data.url('hdChannel.js')];

	for ( i = 1; i <= 9; i++ ) {
		pageMod.PageMod({
			include: ["http://vimeo.com/" + i + "*"],
			contentScriptWhen: 'ready',
			contentScriptFile: scriptFilesSingle,
			onAttach: function(worker) {
				worker.port.emit("loadScript");
			}
		});
	}
	
	for ( i = 1; i <= 9; i++ ) {
		pageMod.PageMod({
			include: ["http://www.vimeo.com/" + i + "*"],
			contentScriptWhen: 'ready',
			contentScriptFile: scriptFilesSingle,
			onAttach: function(worker) {
				worker.port.emit("loadScript");
			}
		});
	}
	
	pageMod.PageMod({
		include: ["http://www.vimeo.com/groups/*"],
		contentScriptWhen: 'ready',
		contentScriptFile: scriptFilesSingle,
		onAttach: function(worker) {
			worker.port.emit("loadScript");
		}
	});
	
	pageMod.PageMod({
		include: ["http://vimeo.com/groups/*"],
		contentScriptWhen: 'ready',
		contentScriptFile: scriptFilesSingle,
		onAttach: function(worker) {
			worker.port.emit("loadScript");
		}
	});

	var pages = {hd:"hd*", staff:"staff*", staff2:"channels/staffpick*"}; 
	
	for (x in pages) {
		pageMod.PageMod({
			include: ["http://vimeo.com/" + pages[x]],
			contentScriptWhen: 'start',
			contentScriptFile: scriptFilesChannels,
			onAttach: function(worker) {
				worker.port.emit("loadScript");
			}
		});	
	}
	
	for (x in pages) {
		pageMod.PageMod({
			include: ["http://www.vimeo.com/" + pages[x]],
			contentScriptWhen: 'start',
			contentScriptFile: scriptFilesChannels,
			onAttach: function(worker) {
				worker.port.emit("loadScript");
			}
		});	
	}
}